package cn.com.suiyi.shixingshengxian.mine.pay;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.google.zxing.integration.android.IntentIntegrator;
import com.google.zxing.integration.android.IntentResult;

import butterknife.ButterKnife;
import butterknife.InjectView;
import butterknife.OnClick;
import cn.com.suiyi.shixingshengxian.R;
import cn.com.suiyi.shixingshengxian.base.BaseActivity;

/**
 * Created by Administrator on 2016/7/20.
 */
public class PayActivity extends BaseActivity {
    @InjectView(R.id.toolbar_pay)
    Toolbar toolbarPay;
    @InjectView(R.id.layout_dimension)
    RelativeLayout layoutDimension;
    @InjectView(R.id.layout_scan)
    RelativeLayout layoutScan;
    @InjectView(R.id.textview_name_pay)
    TextView textviewNamePay;
    @InjectView(R.id.textview_address_pay)
    TextView textviewAddressPay;
    @InjectView(R.id.layout_address_pay)
    RelativeLayout layoutAddressPay;

    @Override
    protected void initData() {

    }

    @Override
    public int getLayout() {
        return R.layout.activity_pay;
    }

    @Override
    public void initView() {

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.pay_bill, menu);
        return true;
    }


    @OnClick({R.id.layout_dimension, R.id.layout_scan, R.id.layout_address_pay})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.layout_dimension:
                break;
            case R.id.layout_scan:
                Log.i("tag", "onClick: ");
                IntentIntegrator integrator = new IntentIntegrator(PayActivity.this);
                integrator.setDesiredBarcodeFormats(IntentIntegrator.ALL_CODE_TYPES);//扫描类型
                integrator.setPrompt("Scan a barcode");
                integrator.setCameraId(0);  // Use a specific camera of the device
                integrator.setBeepEnabled(true);//扫描声音
                integrator.setBarcodeImageEnabled(true);
                integrator.setOrientationLocked(true);//true为竖屏
                integrator.initiateScan();
                break;
            case R.id.layout_address_pay:
                break;
        }
    }
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
        if(result != null) {
            if(result.getContents() == null) {
                Toast.makeText(this, "Cancelled", Toast.LENGTH_LONG).show();
            } else {
                Toast.makeText(this, "Scanned: " + result.getContents(), Toast.LENGTH_LONG).show();
            }
        } else {
            super.onActivityResult(requestCode, resultCode, data);
        }
    }
}
